<?php
class bindadminControl extends skymvc{
	
	public function __construct(){
		parent::__construct();		
	}
	
	public function onInit(){
		M("login")->checkLogin();
	}
	
	public function onDefault(){
		$this->smarty->assign(array(
			"user"=>M("login")->getuser()
		));
		$this->smarty->display("bindadmin/index.html");
	}
	
	public function onWeiXin(){
		$adminname=post('adminname','h');
		$type=get_post('type','h');
		if($type=='shop'){
			$table='shopadmin';
		}else{
			$table=$type."_admin";
		}
		$row=M($table)->selectRow(array("where"=>" adminname='".$adminname."' "));
		if($row && $row['password']==umd5(post('password').$row['salt'])){
			$user=M("login")->getuser();
			if($user['openid'] && $user['xfrom']=='weixin'){
				 M("apppush")->update(array(
				 	$type."admin"=>$row['adminid']
				 ),"userid=".$user['userid']." AND appname='weixin' AND openid='".$user['openid']."' ");
			}else{
				$this->goall("请先在微信登录",1);
			}
			$this->goall("绑定成功",0);
		}else{
			$this->goall("账户或者密码出错",1);
		}
	}
	
	 
	
}
?>